<import file="block/common.html" name="url"/>
<div class="layui-fluid">
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">图集标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="图集标题不能为空" placeholder="请输入图集标题"
                    value="" class="layui-input">
            </div>
        </div>
		<?php if(sysrolTF("upload_imgUpload")){ ?>
		<div class="layui-form-item">
            <label class="layui-form-label required">缩略图</label>
            <div class="layui-input-block">
                <input type="text" id="imageval" name="img" value="" class="layui-input">
				<button type="button" class="layui-btn" id="thumimg">
				  <i class="layui-icon">&#xe67c;</i>上传图片
				</button>
				<tip>200X130px</tip>
            </div>
        </div>
		<?php } ?>
        <div class="layui-form-item">
            <label class="layui-form-label required">作者</label>
            <div class="layui-input-inline">
                <input type="text" name="auther" lay-verify="required" lay-reqtext="作者不能为空" placeholder="请输入作者"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">简要描述</label>
            <div class="layui-input-block">
			 <textarea name="content" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图集状态</label>
            <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="发布">
                <input type="radio" name="status" value="0" title="未审" checked>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveBtn"><?php echo lang('save');?></button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
			upload = layui.upload,
            $ = layui.$;
			
		var uploadInst = upload.render({
			elem: '#thumimg' //绑定元素
			,url: '<{caUrl("upload","imgUpload")}>' //图片上传接口
			,size: 1000
			,accept:'images'
			,acceptMime: 'image/*'
			//,acceptMime: 'image/jpg, image/png'
			,done: function(res){
				if(res.status == 1){
					$('#imageval').val(res.result[0].src);
					layer.msg(res.info);
				}else{
					layer.msg(res.info);
				}
			}
			,error: function(){
			  //请求异常回调
			}
		});
		
		form.render();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post('<{caUrl("image","add")}>', data.field, function (res) {
                if (res.status == 1) {
                    layer.msg(res.info, { icon: 1, time: 1000 }, function () {
                        loadMain('<{caUrl("image","index")}>');
                    });
                } else {
                    layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
                }
            });
            return false;
        });

    });
</script>